﻿<%@ Page Title="" Language="C#" MasterPageFile="../Examples.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="DotNetSources.Web.UI.Buttons.Examples.Examples._8_Repeater.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentDescription" runat="server">
    Buttons with confirm box used in Repeator.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentExample" runat="server">
    Result from server:
    <asp:Label runat="server" ID="lblResult" ForeColor="Red" /><br />
    <hr />
    Repeator:
    <asp:Repeater runat="server" ID="repMain">
        <HeaderTemplate>
            <table>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <%# Eval("Value") %>
                </td>
                <td>
                    <dns:ClassicButton runat="server" OnCommand="DeleteClick" ConfirmText="Do you want to really delete this item?"
                        Text="Delete" CommandName="Delete" CommandArgument='<%# Eval("DelId") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    <hr />
    <strong>Code:</strong>
    <div class="code">
<pre>
ASPX:
        &lt;asp:Repeater runat="server" ID="Repeater1"&gt;
            &lt;HeaderTemplate&gt;
                &lt;table&gt;
            &lt;/HeaderTemplate&gt;
            &lt;ItemTemplate&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;%# Eval("Value") %&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;dns:ClassicButton ID="ClassicButton1" runat="server" OnCommand="DeleteClick" ConfirmText="Do you want to really delete this item?"
                            Text="Delete" CommandName="Delete" CommandArgument='&lt;%# Eval("DelId") %&gt;' /&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/ItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;/table&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:Repeater&gt;
        
C#:
    public partial class Default : BoxContextPage {

        protected void Page_Load(object sender, EventArgs e) {

            DataItemList dil = new DataItemList();
            dil.Add(new DataItem("aaaaa", "1"));
            dil.Add(new DataItem("bbbbb", "2"));
            dil.Add(new DataItem("ccccc", "3"));
            dil.Add(new DataItem("ddddd", "4"));
            dil.Add(new DataItem("eeeee", "5"));
            dil.Add(new DataItem("fffff", "6"));

            repMain.DataSource = dil;
            repMain.DataBind();


        }

        protected void DeleteClick(Object sender, CommandEventArgs e) {
            lblResult.Text = string.Format("Command name: {0}, Command argument: {1}", e.CommandName, e.CommandArgument);
        }

    }


    public class DataItem {
        private string delId;

        public string DelId {
            get { return delId; }
            set { delId = value; }
        }
        private string value;

        public string Value {
            get { return value; }
            set { this.value = value; }
        }

        public DataItem(string value, string id) {
            this.value = value;
            this.delId = id;
        }

    }

    public class DataItemList : List&lt;DataItem&gt; {

    }

</pre>
    </div>
</asp:Content>
